package com.com.knowledgepaymentmanagementsystem.controller.marketing;

import com.com.knowledgepaymentmanagementsystem.pojo.marketing.Seckill;
import com.com.knowledgepaymentmanagementsystem.service.marketing.SeckillService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "秒杀项目管理")
@CrossOrigin
@RequestMapping("/seckill")
public class SeckillController {
    @Autowired
    private SeckillService seckillService;

    @ApiOperation(value = "查询秒杀项目",httpMethod = "POST",notes = "查询秒杀项目")
    @PostMapping("/findSeckill")
    public ResultUtil<List<Seckill>> getPhotos(@RequestBody Seckill seckill){
        List<Seckill> seckills = seckillService.getSeckill(seckill);
        try {
            return new  ResultUtil<>(200,"查询成功",seckills);
        } catch (Exception e) {
            e.printStackTrace();
            return new  ResultUtil<>(200,"查询失败");

        }
    }

    @ApiOperation(value = "新增秒杀项目",httpMethod = "POST",notes = "新增秒杀项目")
    @PostMapping("insertSeckill")
    public ResultUtil insertSeckil(@RequestBody Seckill seckill){
        try {
            return new ResultUtil<>(200,"新增成功",seckillService.insertSeckill(seckill));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "修改秒杀项目",httpMethod = "PUT",notes = "修改秒杀项目")
    @PutMapping("/updateSeckill")
    public ResultUtil updateSeckill(@RequestBody Seckill seckill){

        seckillService.updateSeckill(seckill);
        try {
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");

        }
    }

    @ApiOperation(value = "删除秒杀项目",httpMethod = "DELETE",notes = "删除秒杀项目")
    @DeleteMapping("/deleteSeckill")
    public ResultUtil deleteSeckill(Integer id){
        seckillService.deleteSeckill(id);
        try {
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");

        }
    }
}
